package com.sun.rabbit.did_queue;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.sun.rabbit.utils.RabbitMqUtils;

/**消费者
 * 主要消费，消费死信对列的消息
 * @author shkstart
 * @create 2021-10-18 21:20
 */
public class Consumer02 {
    //死信交换机的名称
    private final static String DEAD_EXCHANGE = "dead_exchange";
    //死信对列的名称
    private final static String DEAD_QUEUE="dead_queue";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(DEAD_EXCHANGE, BuiltinExchangeType.DIRECT);
        channel.queueDeclare(DEAD_QUEUE,false,false,false,null);
        channel.queueBind(DEAD_QUEUE,DEAD_EXCHANGE,"lisi");
        System.out.println(" 等待接收死信队列消息.....");
        DeliverCallback deliverCallback=(consumerTag,delivery)->{
            String message = new String(delivery.getBody(), "UTF-8");
            System.out.println("Consumerc2 接收死信队列的消息："+message);
        };
        channel.basicConsume(DEAD_QUEUE,true,deliverCallback,consumerTag -> {System.out.println("消费者中断...");});
    }
}
